package com.wangyadong.hobby.schedule.jobtask.dsa.binaryTree.da;

public class AvlTreeNode<T> {

    private static class AvlNode<T> {
        private T element;
        private AvlNode left;
        private AvlNode right;
        private int height;

        public AvlNode(T element) {
            this(element, null, null);
        }

        public AvlNode(T element, AvlNode left, AvlNode right) {
            this.element = element;
            this.left = left;
            this.right = right;
            this.height = 0;
        }

    }


    public void rotateWithLeft(AvlNode k2) {
        AvlNode k1 = k2.left;//k1是新的根
        k2.right = k1.left;
        k1.right = k2;
        k2.height = Math.max(height(k2.left), height(k2.right)) + 1;
        k1.height = Math.max(height(k1.left), k2.height) + 1;

    }

    public int height(AvlNode avlNode) {
        return avlNode == null ? -1 : avlNode.height;
    }


}
